from user.models import User
from rest_framework import serializers


class UserSerializer(serializers.ModelSerializer):

    class Meta:
        model = User
        fields = ['id', 'role', 'realName']


class UserTokenSerializer(serializers.ModelSerializer):
    token = serializers.SerializerMethodField()

    class Meta:
        model = User
        fields = ['id', 'role', 'realName', 'token']

    def get_token(self, obj):
        return self.token_data

    def set_token_data(self, token):
        self.token_data = token
